<template>
  <el-table-column :="attrs">

    <template #default="{ row }">
      <ElButton v-if="row.roomNameJson && row.roomNameJson.length > 2" link type="primary" @click="showList(row.roomNameJson)">查看房型</ElButton>
      <span v-else>无房型</span>
    </template>
  </el-table-column>
</template>

<script setup lang="ts">
import { useAttrs } from 'vue'
import { dialog } from '@/utils/dialog'
import RoomDetailTable from './RoomDetailTable.vue'
const attrs = useAttrs()

const getObj = (v: string) => {
  let obj = {}
  try {
    obj = JSON.parse(v)
  } catch{}
  return obj
}

const showList = (value) => {
  const obj = value ? getObj(value) : {}
  const list = []
  for (let key in obj) {
    list.push({ name: key, content: obj[key] })
  }
  dialog(RoomDetailTable, { title: '查看房型',  modalClass: 'custom-dialog' }, { data: list })
}
</script>
